package com.java110.mall.cart.smo.impl;

import com.java110.mall.cart.dao.IStoreOrderDiscountServiceDao;
import com.java110.dto.storeOrder.StoreOrderDiscountDto;
import com.java110.intf.cart.IStoreOrderDiscountInnerServiceSMO;
import com.java110.po.storeOrder.StoreOrderDiscountPo;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.core.base.smo.BaseServiceSMO;
import com.java110.dto.PageDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName FloorInnerServiceSMOImpl
 * @Description 折扣表内部服务实现类
 * @Author wuxw
 * @Date 2019/4/24 9:20
 * @Version 1.0
 * add by wuxw 2019/4/24
 **/
@RestController
public class StoreOrderDiscountInnerServiceSMOImpl extends BaseServiceSMO implements IStoreOrderDiscountInnerServiceSMO {

    @Autowired
    private IStoreOrderDiscountServiceDao storeOrderDiscountServiceDaoImpl;


    @Override
    public int saveStoreOrderDiscount(@RequestBody StoreOrderDiscountPo storeOrderDiscountPo) {
        int saveFlag = 1;
        storeOrderDiscountServiceDaoImpl.saveStoreOrderDiscountInfo(BeanConvertUtil.beanCovertMap(storeOrderDiscountPo));
        return saveFlag;
    }

     @Override
    public int updateStoreOrderDiscount(@RequestBody  StoreOrderDiscountPo storeOrderDiscountPo) {
        int saveFlag = 1;
         storeOrderDiscountServiceDaoImpl.updateStoreOrderDiscountInfo(BeanConvertUtil.beanCovertMap(storeOrderDiscountPo));
        return saveFlag;
    }

     @Override
    public int deleteStoreOrderDiscount(@RequestBody  StoreOrderDiscountPo storeOrderDiscountPo) {
        int saveFlag = 1;
        storeOrderDiscountPo.setStatusCd("1");
        storeOrderDiscountServiceDaoImpl.updateStoreOrderDiscountInfo(BeanConvertUtil.beanCovertMap(storeOrderDiscountPo));
        return saveFlag;
    }

    @Override
    public List<StoreOrderDiscountDto> queryStoreOrderDiscounts(@RequestBody  StoreOrderDiscountDto storeOrderDiscountDto) {

        //校验是否传了 分页信息

        int page = storeOrderDiscountDto.getPage();

        if (page != PageDto.DEFAULT_PAGE) {
            storeOrderDiscountDto.setPage((page - 1) * storeOrderDiscountDto.getRow());
        }

        List<StoreOrderDiscountDto> storeOrderDiscounts = BeanConvertUtil.covertBeanList(storeOrderDiscountServiceDaoImpl.getStoreOrderDiscountInfo(BeanConvertUtil.beanCovertMap(storeOrderDiscountDto)), StoreOrderDiscountDto.class);

        return storeOrderDiscounts;
    }


    @Override
    public int queryStoreOrderDiscountsCount(@RequestBody StoreOrderDiscountDto storeOrderDiscountDto) {
        return storeOrderDiscountServiceDaoImpl.queryStoreOrderDiscountsCount(BeanConvertUtil.beanCovertMap(storeOrderDiscountDto));    }

    public IStoreOrderDiscountServiceDao getStoreOrderDiscountServiceDaoImpl() {
        return storeOrderDiscountServiceDaoImpl;
    }

    public void setStoreOrderDiscountServiceDaoImpl(IStoreOrderDiscountServiceDao storeOrderDiscountServiceDaoImpl) {
        this.storeOrderDiscountServiceDaoImpl = storeOrderDiscountServiceDaoImpl;
    }
}
